﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TuongLaiDangCho.DTO;
using System.Data;
using System.Data.OleDb;

namespace TuongLaiDangCho.DAO
{
    class GhiChuDAO
    {
        public static DataTable LoadNote()
        {
            string sql = "Select * From GHICHU";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            cn.Close();
            return dt;
        }

        public static void InsertNote(GhiChuDTO note)
        {
            string sql = "Insert Into GHICHU(NoiDung,ChuThich) values('" + note.NoiDung + "','" + note.ChuThich + "')";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void UpdateNote(GhiChuDTO note)
        {
            string sql="Update GHICHU set NoiDung='"+note.NoiDung+"' , ChuThich='"+note.ChuThich+"' where ID="+note.ID.ToString()+"";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void DeleteNote(GhiChuDTO note)
        {
            string sql = "Delete From GHICHU where ID=" + note.ID.ToString() + "";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }
    }
}
